package com.fyp.ptma.controllers;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fyp.ptma.dao.service.iservice.IApplicationService;
import com.fyp.ptma.dao.service.iservice.IUserService;
import com.fyp.ptma.model.Application;
import com.fyp.ptma.model.ApplicationVersion;
import com.fyp.ptma.model.ApplicationVersionPk;
import com.fyp.ptma.model.Defect;
import com.fyp.ptma.model.Downloader;
import com.fyp.ptma.model.Group;
import com.fyp.ptma.model.Invitation;
import com.fyp.ptma.model.User;

@Controller
public class DummyData extends AbstractController {

	@Autowired
	private IUserService userService;

	@Autowired
	private IApplicationService applicationService;

	@RequestMapping(value = "/addUser.html", method = RequestMethod.GET)
	public @ResponseBody
	String addDummyUser(HttpServletRequest request, HttpServletResponse response) {

		{
			User user = new User();

			user.setEmail("y@g.com");
			user.setFirstName("Yahya");
			user.setLastName("Arshad");
			user.setPassword("asdfasdf");
			user.setPhoneNumber("0321-3809083");
			long id = 0;
			List<Application> applications = new ArrayList<Application>();
			user.setApplications(applications);
			/***************************************** Downloaders ****************************************************/
			List<Downloader> dwls = new ArrayList<Downloader>();
			{

				{
					Invitation inv = new Invitation();
					Downloader downloader = new Downloader("Motorola Atrix 2",
							" MB 865", "yahya.arshad@gmail.com",
							"356378042257121", inv);

					dwls.add(downloader);
					downloader.setUser(user);
				}

				{
					Invitation inv = new Invitation();
					Downloader downloader = new Downloader("Samsung Glaxy Tab",
							" 7.0", "zain@gmail.com", "Device Id2", inv);

					dwls.add(downloader);
					downloader.setUser(user);
				}

				{
					Invitation inv = new Invitation();
					Downloader downloader = new Downloader("LG Optimus 2x",
							" MB 865", "babar@hotmail.com", "Device Id3", inv);

					dwls.add(downloader);
					downloader.setUser(user);
				}

				{
					Invitation inv = new Invitation();
					Downloader downloader = new Downloader("Google Nexus 7",
							" Nexus", "hl@mobilink.com", "Device Id4", inv);
					downloader.setUser(user);

					dwls.add(downloader);
				}

				user.setDownloaders(dwls);
			}

			// Application // com.ftv.gk
			/*************************************** Application ************************************/

			{
				List<ApplicationVersion> versions = new ArrayList<ApplicationVersion>();

				Application app = new Application();
				app.setAboutApp("About first dummy app text");
				app.setApplicationName("First Than Visual Schedule");
				app.setNameSpace("com.ftv.gk");

				applications.add(app);
				app.setAppVersions(versions);
				app.setUser(user);
				app.setDownloaders(dwls);
				// Versions

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.4"));

					version.setVersionComment("Version 2.0.4 of FTV fixes previous defects");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Please check and report any defect",
							Defect.DEVELOPER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DEVELOPER, version));

					defects.add(new Defect("Every thing seem to work fine",
							Defect.DOWNLOADER, version));

					defects.add(new Defect(
							"I will check it and report defects",
							Defect.DOWNLOADER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.5"));

					version.setVersionComment("While adding new picture application crashes");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"on clicking step image i can't hear any sound",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.6"));

					version.setVersionComment("Previous defect in this version are resolved");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.7"));

					version.setVersionComment("New functionality of downloading images is implemented");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.8"));

					version.setVersionComment("Jerk on scroll of view is fixed");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.9"));

					version.setVersionComment("Previous defects are resolved");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "3.0.0"));

					version.setVersionComment("All functionality you told us are implemented please verify behaviour and check if there is any defect...");

					versions.add(version);
				}

				/***************************************** Groups ****************************************************/

				{
					List<Group> groups = new ArrayList<Group>();
					{
						Group group = new Group("Good Karma Devices");
						group.setDownloaders(dwls);
						groups.add(group);
						group.setUser(user);

					}
					{
						Group group = new Group("GoPro All Devices");
						group.setDownloaders(dwls);
						groups.add(group);
						group.setUser(user);

					}
					{
						Group group = new Group("Smartmicros Developers");
						group.setDownloaders(dwls);
						groups.add(group);
						group.setUser(user);

					}
					user.setGroups(groups);
					app.setGroups(groups);
				}
			}
	 

			/******************************************* Application 2 *************************************************/
			{
				List<ApplicationVersion> versions = new ArrayList<ApplicationVersion>();

				Application app = new Application();
				app.setAboutApp("This application is about current affairs going on in world, This application will provide latest news about world's news and current affair, again FYI it is a dummy app");
				app.setApplicationName("Know Current Affairs of Pakistan and World");
				app.setNameSpace("com.current.affair.pk");

				applications.add(app);
				app.setAppVersions(versions);
				app.setUser(user);
				app.setDownloaders(dwls);
				// Versions

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.4"));

					version.setVersionComment("Version 2.0.4 of Current Affair fixes previous defects");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Please check and report any defect",
							Defect.DEVELOPER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DEVELOPER, version));

					defects.add(new Defect("Every thing seem to work fine",
							Defect.DOWNLOADER, version));

					defects.add(new Defect(
							"I will check it and report defects",
							Defect.DOWNLOADER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.5"));

					version.setVersionComment("While adding new picture application crashes");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"on clicking step image i can't hear any sound",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.6"));

					version.setVersionComment("Previous defect in this version are resolved");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.7"));

					version.setVersionComment("New functionality of downloading images is implemented");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.8"));

					version.setVersionComment("Jerk on scroll of view is fixed");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "2.0.9"));

					version.setVersionComment("Previous defects are resolved");
					List<Defect> defects = new ArrayList<Defect>();
					defects.add(new Defect(
							"Dummy defect is that i can't delete my schedule",
							Defect.DOWNLOADER, version));
					defects.add(new Defect(
							"Please don't report one defect twice",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("On image click sound is resolved",
							Defect.DOWNLOADER, version));

					defects.add(new Defect("Crash is fixed", Defect.DOWNLOADER,
							version));

					defects.add(new Defect(
							"Now you can delete your schedule please check",
							Defect.DEVELOPER, version));

					version.setDefects(defects);
					versions.add(version);
				}

				{
					ApplicationVersion version = new ApplicationVersion(++id,
							new ApplicationVersionPk(app, "3.0.0"));

					version.setVersionComment("All functionality you told us are implemented please verify behaviour and check if there is any defect...");

					versions.add(version);
				}

				/***************************************** Downloaders ****************************************************/

				/***************************************** Groups ****************************************************/

				{
					List<Group> groups = new ArrayList<Group>();
					{
						Group group = new Group("Good Karma Devices");
						group.setDownloaders(dwls);
						groups.add(group);

					}
					{
						Group group = new Group("GoPro All Devices");
						group.setDownloaders(dwls);
						groups.add(group);

					}
					{
						Group group = new Group("Smartmicros Developers");
						group.setDownloaders(dwls);
						groups.add(group);

					}
					user.setGroups(groups);
					app.setGroups(groups);
				}

			}
			userService.save(user);
		}
		return "Ok";
	}
}
